package com.bdqn.demo01.service;

import com.bdqn.demo01.dao.NewsDao;
import com.bdqn.demo01.entity.News;

import java.util.List;

/**
 * NewsServiceImpl
 *
 * @author LILIBO
 * @since 2022-09-24
 */
public class NewsServiceImpl implements NewsService {
    // ① 直接实例化一个对象，依赖了NewsDaoOracleImpl类
    // NewsDao newsDao = new NewsDaoOracleImpl();

    // ② 依赖倒置，通过set方法或者构造方法进行传递
    NewsDao newsDao;

    /**
     * 通过构造方法传递需要依赖的DAO实现类
     *
     * @param newsDao
     */
    public NewsServiceImpl(NewsDao newsDao) {
        this.newsDao = newsDao;
    }

    /**
     * 需要使用什么DAO实现版本由你自己决定
     *
     * @param newsDao
     */
    public void setDao(NewsDao newsDao) {
        this.newsDao = newsDao;
    }

    @Override
    public List<News> list() {
        return newsDao.list();
    }

}
